//
// Created by shen on 2025/2/22.
//

#ifndef VIDEOEDIT_VIDEOPLAYER_H
#define VIDEOEDIT_VIDEOPLAYER_H
#include <BaseGLRender.h>
#include "AVFrameQueue.h"
#include "BasePlayer.h"
#include "SLog.h"

#include "VideoGLRender.h"
#include <mutex>
#include "AudioPlayer.h"
#include "LogUtil.h"
extern "C"{
#include "libavutil/time.h"
#include "libavcodec/avcodec.h"
#include "libavutil/imgutils.h"
#include "libswscale/swscale.h"
};
class VideoPlayer: public BasePlayer{
    static void *videoPlay(void *arg);

public:
    explicit VideoPlayer(FFStatus *ffstatus);
    ~VideoPlayer() override;

    void OnFrameAvailable(AVFrame *frame) override;
    double getFrameDiffTime(AVFrame *avFrame,AVPacket *aPacketFrame);
    double getDelayTime(double diff);
    double delayTime = 0;

    VideoRender * getGLRender();
    void setGLRender(VideoRender *baseGLRender);
public:
    AVFrameQueue *frameQueue = NULL;

    VideoRender *videoRender = nullptr;

    int64_t seekTime = 0;

    double showFrameTimestamp = 0;//拖动预览条后当前显示的帧的时间
    void play() override;

//    AVFrameQueue *frameQueue = NULL;

     AudioPlayer *audioPlayer = NULL;


    double lock = 0;

    //队列中缓存的帧的数量
    int cacheFrameNum = 60;
};


#endif //VIDEOEDIT_VIDEOPLAYER_H
